# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=snap-core
pkgname=haskell-snap-core
pkgver=1.0.5.1
pkgrel=46
pkgdesc="A Haskell Web Framework (core interfaces and types)"
url="https://github.com/snapframework/snap-core"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-old-locale' 'haskell-hunit' 'haskell-attoparsec'
         'haskell-case-insensitive' 'haskell-lifted-base' 'haskell-io-streams' 'haskell-hashable'
         'haskell-monad-control' 'haskell-random' 'haskell-readable' 'haskell-regex-posix'
         'haskell-transformers-base' 'haskell-unix-compat' 'haskell-unordered-containers'
         'haskell-vector' 'haskell-network' 'haskell-network-uri')
makedepends=('ghc' 'uusi' 'haskell-quickcheck' 'haskell-parallel' 'haskell-test-framework'
             'haskell-test-framework-hunit' 'haskell-test-framework-quickcheck2' 'haskell-zlib')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('1b4c15d0aa2d73cb09df32dbc2d2c4057f6dbd548d5c53350462b1b3dd0d892a7f7ee2726ac5a1c7fdc6070cebdbb24295c23595f662fad58300b0f5c0ae91b8')

prepare() {
    cd $_hkgname-$pkgver
    uusi -d bytestring-builder -u unix-compat $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
